//This file performs the main empirical analysis for the paper "Treasury Re-use and the Demand for Safe Assets"
//The input file is "treasuryReusePseudoData.xlsx", a pseudo-data set that contains randomized versions of the variables used in our analysis. As such, the results output by this file will not match those shown in the paper.
//The accompanying file "treasuryReusePseudoDataDictionary.pdf" provides definitions for the variables contained in the pseudo-data set


clear 
frames reset

capture log close

//////////////////////// Load and clean data ////////////////////////

cd /fst/res-m1zcs00/repo/collatReuse/drafts/rfs/finalSubmission

global output "/fst/res-m1zcs00/repo/collatReuse/drafts/rfs/finalSubmission"

import excel treasuryReusePseudoData.xlsx,firstrow

//destring vars from csv
destring  year	month	day	DealerID	allContracts	repo	nonRehyAllContracts	USText	USTextRP	dealerCDS	bondsOutstanding	notesOutstanding	shortBillOutstanding	allBillOutstanding	notesAndBondsOutstanding	tbillFourWeek	OIS1M	convYieldOneMonthCP	tprRate	gcfRate	sofr	brokertecOtrSpecialness	vix	ustSomaHoldings	somaBills	somaNotes	somaBonds	reserves	fedReverseRepo	yield10yr	yield2yr	quarterEndDummy, force replace


////Import date and change to date format
gen date = mdy(month, day, year)
format date %td 

//Dropping obs after year-end 2022
drop if (year > 2022) | (year == 2022 & month > 3)

gen yq = qofd(date)
gen ym = mofd(date)
gen quart = quarter(date)

format yq %tq
format ym %tm

egen ym_dealer = group(ym DealerID)
egen yq_dealer = group(yq DealerID)

///in order to use time series operators
xtset, clear
sort DealerID date 
bysort DealerID: gen time= _n
xtset DealerID time

///Adjust units of SOMA maturity vars into dollars, from billions of dollars
replace somaBills = somaBills * 1000000000
replace somaNotes = somaNotes * 1000000000
replace somaBonds = somaBonds * 1000000000

//One day changes in supply & dealer inventory
gen TBillLogGr = log(allBillOutstanding) - log(L.allBillOutstanding)
gen ShTBillLogGr = log(shortBillOutstanding) - log(L.shortBillOutstanding)
gen USTNotesLogGr = log(notesOutstanding) - log(L.notesOutstanding)
gen USTBondsLogGr = log(bondsOutstanding) - log(L.bondsOutstanding)
gen USTCouponsLogGr = log(notesAndBondsOutstanding) - log(L.notesAndBondsOutstanding)
gen SOMALogGr = log(ustSomaHoldings) - log(L.ustSomaHoldings)
gen SOMABillsLogGr = log(somaBills) - log(L.somaBills)
gen SOMANotesLogGr = log(somaNotes) - log(L.somaNotes)
gen SOMABondsLogGr = log(somaBonds) - log(L.somaBonds)
gen ReservesLogGr = log(reserves) - log(L.reserves)
gen RRPLogGr = log(fedReverseRepo) - log(L.fedReverseRepo)

//Becuase SOMA Bills is zero for large part of sample, need to replace NAs generated from taking log change of zero
quietly replace SOMABillsLogGr = 0 if missing(SOMABillsLogGr)

//Generate spread variables
gen CY1M = - tbillFourWeek + OIS1M
gen Sp = brokertecOtrSpecialness
gen GCF_sp = gcfRate - tprRate
gen USTslope = yield10yr - yield2yr
gen CY1MCP = convYieldOneMonthCP

///time dummies for mid-march change in policy
gen indMidMarch2020 = 0
replace indMidMarch2020 = 1 if date >= td(15mar2020) & date < td(01apr2020)
gen indMarch2020 = 0
replace indMarch2020 = 1 if date >= td(01mar2020) & date < td(01apr2020)
gen indMarchApril2020 = 0
replace indMarchApril2020 = 1 if date >= td(01mar2020) & date <= td(30apr2020)
///Add dummy for SLR carve-out period
gen indSlrCarveout = 0
replace indSlrCarveout = 1 if date >= td(01apr2020) & date <= td(31mar2021)

//Quarter-end dummy for daily regs
gen QEDummy = quarterEndDummy
//replace QEDummy = 1 if L.quarterEndDummy == 1 | F.quarterEndDummy == 1
replace QEDummy = 1 if L.quarterEndDummy == 1 | F.quarterEndDummy == 1 | L2.quarterEndDummy == 1 | F2.quarterEndDummy == 1 

///Exclude quarter end dates for daily regs
replace USText = . if QEDummy == 1 
replace USTextRP = . if QEDummy == 1 
replace allContracts = . if QEDummy == 1 
replace repo = . if QEDummy == 1 
replace nonRehyAllContracts = . if QEDummy == 1 

/*
///Exclude repo spike of Sept 2019
replace USText = . if date == td(17sep2019) | date == td(16sep2019)
replace USTextRP = . if date == td(17sep2019) | date == td(16sep2019)
replace USTextBilat = . if date == td(17sep2019) | date == td(16sep2019)
*/

///Log changes for CMs, daily
gen CM_LogGr = log(USText) - log(L.USText)
gen CMRP_LogGr = log(USTextRP) - log(L.USTextRP)
gen AC_LogGr = log(allContracts) - log(L.allContracts)
gen RP_LogGr = log(repo) - log(L.repo)
gen NonRehy_LogGr = log(nonRehyAllContracts) - log(L.nonRehyAllContracts)

//////////////////////// Summary Stats ////////////////////////

//Table 1 - Summary Stats

//Create new frame to adjust vars for summary stats (multiplying by 1000 and collapsing time series vars)
frame copy default sumStats
frame change sumStats

//Multiplying log changes by 1000
replace CM_LogGr = CM_LogGr * 1000
replace CMRP_LogGr = CMRP_LogGr * 1000

//Output sum stats for log changes of CMs
estpost summarize CM_LogGr CMRP_LogGr, detail
eststo cmLogGrSumStats
esttab cmLogGrSumStats using "$output/cmLogGrSumStats.tex",b(a3) replace cells("mean(fmt(%5.3f)) sd(fmt(%5.3f)) p5(fmt(%5.3f)) p95(fmt(%5.3f)) count(fmt(%5.0f))")

//Output sum stats for levels of CMs
estpost summarize USText USTextRP, detail
eststo cmLevelsSumStats
esttab cmLevelsSumStats using "$output/cmLevelsSumStats.tex",b(a3) replace cells("mean(fmt(%5.3f)) sd(fmt(%5.3f)) p5(fmt(%9.3f)) p95(fmt(%5.3f)) count(fmt(%5.0f))")


//Creating separate summary stats for time series vars

//collapse to time series
collapse ShTBillLogGr TBillLogGr USTNotesLogGr USTBondsLogGr USTCouponsLogGr SOMALogGr SOMABillsLogGr SOMANotesLogGr SOMABondsLogGr ReservesLogGr RRPLogGr shortBillOutstanding allBillOutstanding notesOutstanding bondsOutstanding notesAndBondsOutstanding ustSomaHoldings somaBills somaNotes somaBonds  reserves fedReverseRepo, by(date)

//Multiplying log change vars by 1000
replace ShTBillLogGr = ShTBillLogGr * 1000
replace TBillLogGr = TBillLogGr * 1000
replace USTCouponsLogGr = USTCouponsLogGr * 1000
replace USTNotesLogGr = USTNotesLogGr * 1000
replace USTBondsLogGr = USTBondsLogGr * 1000
replace SOMALogGr = SOMALogGr * 1000
replace SOMABillsLogGr = SOMABillsLogGr * 1000
replace SOMANotesLogGr = SOMANotesLogGr * 1000
replace SOMABondsLogGr = SOMABondsLogGr * 1000


//Output sum stats for log changes of time series vars
estpost summarize ShTBillLogGr TBillLogGr USTNotesLogGr USTBondsLogGr USTCouponsLogGr SOMALogGr SOMABillsLogGr SOMANotesLogGr SOMABondsLogGr, detail
eststo tsLogGrSumStats
esttab tsLogGrSumStats using "$output/tsLogGrSumStats.tex",b(a3) replace cells("mean(fmt(%5.3f)) sd(fmt(%5.3f)) p5(fmt(%5.3f)) p95(fmt(%5.3f)) count(fmt(%5.0f))")

//Multiplying level vars by 1000
replace shortBillOutstanding = shortBillOutstanding/10^12
replace allBillOutstanding = allBillOutstanding/10^12
replace notesAndBondsOutstanding = notesAndBondsOutstanding/10^12
replace notesOutstanding = notesOutstanding/10^12
replace bondsOutstanding = bondsOutstanding/10^12
replace ustSomaHoldings = ustSomaHoldings/10^12
replace somaBills = somaBills/10^12
replace somaNotes = somaNotes/10^12
replace somaBonds = somaBonds/10^12

//Output sum stats for levels of time series vars
estpost summarize shortBillOutstanding allBillOutstanding notesOutstanding bondsOutstanding notesAndBondsOutstanding ustSomaHoldings somaBills somaNotes somaBonds, detail
eststo tsLevelsSumStats
esttab tsLevelsSumStats using "$output/tslevelsSumStats.tex", replace cells("mean(fmt(%5.3f)) sd(fmt(%5.3f)) p5(fmt(%5.3f)) p95(fmt(%5.3f)) count(fmt(%5.0f))")

//change back to panel data
frame change default

//////////////////////// Supply Regs ////////////////////////

//Winsorize daily and weekly CM vars
winsor2 CM_LogGr CMRP_LogGr AC_LogGr RP_LogGr NonRehy_LogGr, cuts(1 , 99) replace

///Create control var groups
global USTcontrol "TBillLogGr USTCouponsLogGr SOMALogGr"
global FINcontrol "L.USTslope L.vix L.sofr" 

//Table 2 - Total and Repo Collateral Multiplier Daily Supply Regressions with Year-Month-Dealer Fixed Effects
	
//Estimate daily baseline regs with year-month-dealer FE
foreach var in CM CMRP {	
	xtscc `var'_LogGr L(1/4).`var'_LogGr L.CY1M L.Sp L.GCF_sp L.dealerCDS TBillLogGr USTCouponsLogGr SOMALogGr $FINcontrol i.ym_dealer, lag(21)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	eststo `var'_ym_dealer		
//Add in Fed liabilities controls	
	xtscc `var'_LogGr L(1/4).`var'_LogGr L.CY1M L.Sp L.GCF_sp L.dealerCDS TBillLogGr USTCouponsLogGr SOMALogGr ReservesLogGr RRPLogGr $FINcontrol i.ym_dealer, lag(21)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	eststo `var'_ym_dealer_liab		
}

//Output daily baseline regs with year-month-dealer FE
estout CM_ym_dealer CMRP_ym_dealer CM_ym_dealer_liab CMRP_ym_dealer_liab using "$output/baseline.txt", replace ///
	varlabels(TBillLogGr  "$\Delta log(TBillsOut_t)$"  USTNotesLogGr "$\Delta log(USTNotesOut_t)$" USTBondsLogGr "$\Delta log(USTBondsOut_t)$" USTCouponsLogGr "$\Delta log(USTCouponsOut_t)$" SOMALogGr "$\Delta log(SOMA_t)$" SOMABillsLogGr "$\Delta log(SOMABills_t)$" SOMANotesLogGr "$\Delta log(SOMANotes_t)$" SOMABondsLogGr "$\Delta log(SOMABonds_t)$" ReservesLogGr "$\Delta log(Reserves_t)$" RRPLogGr "$\Delta log(FedRRP_t)$") ///
	order(TBillLogGr USTCouponsLogGr SOMALogGr) keep(TBillLogGr USTCouponsLogGr SOMALogGr) ///
	cells(b(star fmt(%9.3f))  se(fmt(3) par label(t-stat))) stats(r2_store N, fmt(3 0) labels("Adj RSq " "N obs")) ///
	nolegend label abbrev starl(* 0.1 ** 0.05 *** 0.01) ///
	title("Total and Repo Collateral Multiplier Daily Supply Regressions with Year-Month-Dealer Fixed Effects") ///	
	varwidth(40) modelwidth(20) style(tex) drop()

//Table 3 - Total and Repo Collateral Multiplier Daily Supply Regressions Separating Treasury Bills, Notes, and Bonds, with Year-Month-Dealer Fixed Effects
	
//Estimate daily baseline regs, separating coupon types, with year-month-dealer FE
foreach var in CM CMRP {	
	xtscc `var'_LogGr L(1/4).`var'_LogGr L.CY1M L.Sp L.GCF_sp L.dealerCDS TBillLogGr USTNotesLogGr USTBondsLogGr SOMABillsLogGr SOMANotesLogGr SOMABondsLogGr $FINcontrol i.ym_dealer, lag(21)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	eststo `var'_ym_dealer		
//Add in Fed liabilities controls		
	xtscc `var'_LogGr L(1/4).`var'_LogGr L.CY1M L.Sp L.GCF_sp L.dealerCDS TBillLogGr USTNotesLogGr USTBondsLogGr SOMABillsLogGr SOMANotesLogGr SOMABondsLogGr ReservesLogGr RRPLogGr $FINcontrol i.ym_dealer, lag(21)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	eststo `var'_ym_dealer_liab		
}

//Output daily baseline regs, separating coupon types, with year-month-dealer FE
estout CM_ym_dealer CMRP_ym_dealer CM_ym_dealer_liab CMRP_ym_dealer_liab using "$output/baselineCouponsSep.txt", replace ///
	varlabels(TBillLogGr  "$\Delta log(TBillsOut_t)$"  USTNotesLogGr "$\Delta log(USTNotesOut_t)$" USTBondsLogGr "$\Delta log(USTBondsOut_t)$" USTCouponsLogGr "$\Delta log(USTCouponsOut_t)$" SOMABillsLogGr "$\Delta log(SOMABills_t)$" SOMANotesLogGr "$\Delta log(SOMANotes_t)$" SOMABondsLogGr "$\Delta log(SOMABonds_t)$" ReservesLogGr "$\Delta log(Reserves_t)$" RRPLogGr "$\Delta log(FedRRP_t)$") ///
	order(TBillLogGr USTNotesLogGr USTBondsLogGr SOMABillsLogGr SOMANotesLogGr SOMABondsLogGr) keep(TBillLogGr USTNotesLogGr USTBondsLogGr SOMABillsLogGr SOMANotesLogGr SOMABondsLogGr) ///
	cells(b(star fmt(%9.3f))  se(fmt(3) par label(t-stat))) stats(r2_store N, fmt(3 0) labels("Adj RSq " "N obs")) ///
	nolegend label abbrev starl(* 0.1 ** 0.05 *** 0.01) ///
	title("Total and Repo Collateral Multiplier Daily Supply Regressions Separating Treasury Bills, Notes, and Bonds, with Year-Month-Dealer Fixed Effects") ///	
	varwidth(40) modelwidth(20) style(tex) drop()
	
//Table 4 - Total, Repo, and Non-rehypothecated Volumes Daily Supply Regressions with Year-Month-Dealer Fixed Effects
	
//Estimate daily baseline regs for volumes with year-month-dealer FE	
foreach var in AC RP NonRehy {	
	xtscc `var'_LogGr L(1/4).`var'_LogGr L.CY1M L.Sp L.GCF_sp  L.dealerCDS $FINcontrol  $USTcontrol i.ym_dealer, lag(21)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	eststo `var'_ym_dealer	
//Add in Fed liabilities controls			
	xtscc `var'_LogGr L(1/4).`var'_LogGr L.CY1M L.Sp L.GCF_sp  L.dealerCDS $FINcontrol  $USTcontrol ReservesLogGr RRPLogGr i.ym_dealer, lag(21)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	eststo `var'_ym_dealer_liab		
}	


//Output daily baseline regs with for volumes with year-month-dealer FE
estout AC_ym_dealer RP_ym_dealer NonRehy_ym_dealer AC_ym_dealer_liab RP_ym_dealer_liab NonRehy_ym_dealer_liab using "$output/volumesBaseline.txt", replace ///
	varlabels( L.Sp "$(SOFR-RpSpecial)_{t-1}$ "  L.CY1M "$(OIS - Tbill)_{t-1}$" L.GCF_sp "$(GCF-TPR)_{t-1}$ "   TBillLogGr  "$\Delta log(TBillsOut_t)$" USTCouponsLogGr "$\Delta log(USTCouponsOut_t)$" SOMALogGr "$\Delta log(SOMA_t)$" ReservesLogGr "$\Delta log(Reserves_t)$" RRPLogGr "$\Delta log(FedRRP_t)$") ///
	order(TBillLogGr USTCouponsLogGr SOMALogGr ReservesLogGr RRPLogGr) keep(TBillLogGr USTCouponsLogGr SOMALogGr ReservesLogGr RRPLogGr) ///
	cells(b(star fmt(%9.3f))  se(fmt(3) par label(t-stat))) stats(P_Lag r2_store N, fmt(3 3 0) labels("Adj RSq " "N obs")) ///
	nolegend label abbrev starl(* 0.1 ** 0.05 *** 0.01) ///
	title("Total and Repo Collateral Multiplier Daily Supply Regressions Separating Treasury Bills, Notes, and Bonds, with Year-Month-Dealer Fixed Effects") ///	
	varwidth(40) modelwidth(20) style(tex) drop()
	
	
//////////////////////// Safe Asset IV Regs ////////////////////////	
global GovAggLag_exSh "L.USTCouponsLogGr L.SOMALogGr"	
	
//Table 5 - Daily Instrumental Variable Regression Instrumenting CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects

foreach var in CM CMRP {			
	ivreg2 `var'_LogGr L(1/4).`var'_LogGr L.Sp L.GCF_sp L.dealerCDS L.ReservesLogGr L.RRPLogGr $FINcontrol $GovAggLag_exSh (L.CY1M = L.ShTBillLogGr) i.ym_dealer, partial(i.ym_dealer)  dkraay(21) ffirst savefirst savefprefix("`var'_FS")
	//estadd scalar r2_store = e(r2_w)
	////using the F-statistics
	///estadd scalar FStg1 = e(F)
	estadd scalar FStg1 = e(sstat)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	est store `var'_IV_CY		
}

estout  CM_FSL_CY1M CM_IV_CY CMRP_FSL_CY1M CMRP_IV_CY using "$output/ivCY1M.txt", replace  ///
	varlabels(L.Sp "$(SOFR-RpSpecial)_{t-1}$ "  L.CY1M "$(OIS - Tbill)_{t-1}$" L.GCF_sp "$(GCF-TPR)_{t-1}$ " TBillLogGr  "$\Delta log(TBillsOut_t)$" L.USTCouponsLogGr "$\Delta log(USTCouponsOut_{t-1})$" L.SOMALogGr "$\Delta log(SOMA_{t-1})$" NonRehyLogGr  "$\Delta log(NonRehy_t)$" RehyLogGr  "$\Delta log(Rehy_t)$"  L.ShTBillLogGr  "$\Delta log(ShTBillsOut_{t-1})$" L.ReservesLogGr "$\Delta log(Reserves_{t-1})$" L.RRPLogGr "$\Delta log(FedRRP_{t-1})$")  ///
	style (tex) cells(b(star fmt(3) label(Coef)) se(fmt(3) par label(se))) ///
	order(L.CY1M L.ShTBillLogGr) keep(L.CY1M L.ShTBillLogGr)  /// 
	stats(FStg1 N, labels("F Stage-1" "N obs") fmt(3 0)) ///
	starlevels(* 0.1 ** 0.05 *** 0.01)  ///	
	title("Daily Instrumental Variable Regression Instrumenting CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects") ///	
	varwidth(40) modelwidth(20)  
	
//Table 6 - Daily Instrumental Variable Regression of Volumes Instrumenting CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects
		
foreach var in AC RP NonRehy {		
	ivreg2 `var'_LogGr L(1/4).`var'_LogGr L.Sp L.GCF_sp L.dealerCDS $FINcontrol $GovAggLag_exSh L.ReservesLogGr L.RRPLogGr (L.CY1M = L.ShTBillLogGr) i.ym_dealer, partial(i.ym_dealer)  dkraay(21) ffirst savefirst savefprefix("`var'_FS")
	//estadd scalar r2_store = e(r2_w)
	////using the F-statistics
	///estadd scalar FStg1 = e(F)
	estadd scalar FStg1 = e(sstat)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	est store `var'_IV_CY	
}

estout  AC_FSL_CY1M AC_IV_CY RP_FSL_CY1M RP_IV_CY NonRehy_FSL_CY1M NonRehy_IV_CY using "$output/volumesIvCY1M.txt", replace  ///
	varlabels(L.Sp "$(SOFR-RpSpecial)_{t-1}$ "  L.CY1M "$(OIS - Tbill)_{t-1}$" L.GCF_sp "$(GCF-TPR)_{t-1}$ " TBillLogGr  "$\Delta log(TBillsOut_t)$" USTCouponsLogGr "$\Delta log(USTCouponsOut_t)$" SOMALogGr "$\Delta log(SOMA_t)$" NonRehyLogGr  "$\Delta log(NonRehy_t)$" RehyLogGr  "$\Delta log(Rehy_t)$"  L.ShTBillLogGr  "$\Delta log(ShTBillsOut_{t-1})$" L.ReservesLogGr "$\Delta log(Reserves_{t-1})$" L.RRPLogGr "$\Delta log(FedRRP_{t-1})$")  ///
	style (tex) cells(b(star fmt(3) label(Coef)) se(fmt(3) par label(se))) ///
	order(L.CY1M L.ShTBillLogGr) keep(L.CY1M L.ShTBillLogGr )  /// 
	stats(FStg1 N, labels("F Stage-1" "N obs") fmt(3 0)) ///
	starlevels(* 0.1 ** 0.05 *** 0.01)  ///	
	title("Daily Instrumental Variable Regression of Volumes Instrumenting CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects") ///	
	varwidth(40) modelwidth(20)  	

//Table 7 - Daily Instrumental Variable Regression Instrumenting Alternate CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects	
	
foreach var in CM CMRP {			
	ivreg2 `var'_LogGr L(1/4).`var'_LogGr L.Sp L.GCF_sp L.dealerCDS $FINcontrol $GovAggLag_exSh L.ReservesLogGr L.RRPLogGr (L.CY1MCP = L.ShTBillLogGr) i.ym_dealer, partial(i.ym_dealer)  dkraay(21) ffirst savefirst savefprefix("`var'_1MCP_FS")
	//estadd scalar r2_store = e(r2_w)
	////using the F-statistics
	///estadd scalar FStg1 = e(F)
	estadd scalar FStg1 = e(sstat)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	est store `var'_1MCP_IV_CY	
}

estout  CM_1MCP_FSL_CY1MCP CM_1MCP_IV_CY CMRP_1MCP_FSL_CY1MCP CMRP_1MCP_IV_CY using "$output/ivCY1MCP.txt", replace  ///
	varlabels(L.Sp "$(SOFR-RpSpecial)_{t-1}$ "  L.CY1MCP "$(CP - Tbill)_{t-1}$" L.GCF_sp "$(GCF-TPR)_{t-1}$ " TBillLogGr  "$\Delta log(TBillsOut_t)$" L.USTCouponsLogGr "$\Delta log(USTCouponsOut_{t-1})$" L.SOMALogGr "$\Delta log(SOMA_{t-1})$" NonRehyLogGr  "$\Delta log(NonRehy_t)$" RehyLogGr  "$\Delta log(Rehy_t)$"  L.ShTBillLogGr  "$\Delta log(ShTBillsOut_{t-1})$" L.ReservesLogGr "$\Delta log(Reserves_{t-1})$" L.RRPLogGr "$\Delta log(FedRRP_{t-1})$")  ///
	style (tex) cells(b(star fmt(3) label(Coef)) se(fmt(3) par label(se))) ///
	order(L.CY1MCP L.ShTBillLogGr) keep(L.CY1MCP L.ShTBillLogGr)  /// 
	stats(FStg1 N, labels("F Stage-1" "N obs") fmt(3 0)) ///
	starlevels(* 0.1 ** 0.05 *** 0.01)  ///	
	title("Daily Instrumental Variable Regression Instrumenting Alternate CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects") ///	
	varwidth(40) modelwidth(20)  
	
//Table 8 - Daily Instrumental Variable Regression of Volumes Instrumenting Alternate CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects			
	
foreach var in AC RP NonRehy {		
	ivreg2 `var'_LogGr L(1/4).`var'_LogGr L.Sp L.GCF_sp L.dealerCDS $FINcontrol $GovAggLag_exSh L.ReservesLogGr L.RRPLogGr (L.CY1MCP = L.ShTBillLogGr) i.ym_dealer, partial(i.ym_dealer)  dkraay(21) ffirst savefirst savefprefix("`var'_1MCP_FS")
	//estadd scalar r2_store = e(r2_w)
	////using the F-statistics
	///estadd scalar FStg1 = e(F)
	estadd scalar FStg1 = e(sstat)
	test  L.`var'_LogGr = L2.`var'_LogGr = L3.`var'_LogGr = L4.`var'_LogGr = 0
	estadd scalar P_Lag = r(p)
	estadd scalar r2_store = e(r2)
	est store `var'_1MCP_IV_CY	
}

estout  AC_1MCP_FSL_CY1MCP AC_1MCP_IV_CY RP_1MCP_FSL_CY1MCP RP_1MCP_IV_CY NonRehy_1MCP_FSL_CY1MCP NonRehy_1MCP_IV_CY using "$output/volumesIvCY1MCP.txt", replace  ///
	varlabels(L.Sp "$(SOFR-RpSpecial)_{t-1}$ "  L.CY1MCP "$(CP - Tbill)_{t-1}$" L.GCF_sp "$(GCF-TPR)_{t-1}$ " TBillLogGr  "$\Delta log(TBillsOut_t)$" USTCouponsLogGr "$\Delta log(USTCopuonsOut_t)$" SOMALogGr "$\Delta log(SOMA_t)$" NonRehyLogGr  "$\Delta log(NonRehy_t)$" RehyLogGr  "$\Delta log(Rehy_t)$"  L.ShTBillLogGr  "$\Delta log(ShTBillsOut_{t-1})$" L.ReservesLogGr "$\Delta log(Reserves_{t-1})$" L.RRPLogGr "$\Delta log(FedRRP_{t-1})$")  ///
	style (tex) cells(b(star fmt(3) label(Coef)) se(fmt(3) par label(se))) ///
	order(L.CY1MCP L.ShTBillLogGr) keep(L.CY1MCP L.ShTBillLogGr )  /// 
	stats(FStg1 N, labels("F Stage-1" "N obs") fmt(3 0)) ///
	starlevels(* 0.1 ** 0.05 *** 0.01)  ///	
	title("Daily Instrumental Variable Regression of Volumes Instrumenting Alternate CY with Short-Term T-Bills Issuance with Year-Month-Dealer Fixed Effects	") ///	
	varwidth(40) modelwidth(20)  	

	
